package com.weeego.web.AbstractInterceptor;

import java.util.Map;

import org.apache.log4j.Logger;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.sql.weeego.bean.base.CenterUser;

public class LoginInterceptor extends AbstractInterceptor {
	public static final String LOGIN_KEY = "user";
	public static final String LOGIN_PAGE = "nologin";
	private String commondResult = "";
	protected final Logger logger = Logger.getLogger(getClass());

	public String getCommondResult() {
		return commondResult;
	}

	public void setCommondResult(String commondResult) {
		this.commondResult = commondResult;
	}

	@Override
	public String intercept(ActionInvocation actionInvocation) throws Exception {

		Map session = actionInvocation.getInvocationContext().getSession();
		CenterUser _CenterUser = (CenterUser) session.get(LOGIN_KEY);
		if (_CenterUser != null) {
			// 存在的情况下进行后续操作。
			logger.info("----------------------------------------"
					+ _CenterUser + "|||actionInvocation.invoke()");

			return actionInvocation.invoke();
		} else {
			// 否则终止后续操作，返回LOGIN
			commondResult = "login";
			return LOGIN_PAGE;
		}
	}
}
